<!--
@license
Copyright (C) 2018 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
<link rel="import" href="../../../bower_components/iron-input/iron-input.html">
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../styles/gr-form-styles.html">
<link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../../shared/gr-button/gr-button.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">

<dom-module id="gr-cla-view">
  <template>
    <style include="shared-styles">
      h1 {
        margin-bottom: .6em;
      }
      h3 {
        margin-bottom: .5em;
      }
      .agreementsUrl {
        border: 0.1em solid #b0bdcc;
        margin-bottom: 1.25em;
        margin-left: 1.25em;
        margin-right: 1.25em;
        padding: 0.3em;
      }
      #claNewAgreementsLabel {
        font-weight: var(--font-weight-bold);
      }
      #claNewAgreement {
        display: none;
      }
      #claNewAgreement.show {
        display: block;
      }
      .contributorAgreementButton {
        font-weight: var(--font-weight-bold);
      }
      .alreadySubmittedText {
        color: var(--error-text-color);
        margin: 0 2em;
        padding: .5em;
      }
      .alreadySubmittedText.hide,
      .hideAgreementsTextBox {
        display: none;
      }
      main {
        margin: 2em auto;
        max-width: 50em;
      }
    </style>
    <style include="gr-form-styles"></style>
    <main>
      <h1>新增贡献者协议</h1>
      <h3>选择一个协议类型:</h3>
      <template is="dom-repeat" items="[[_serverConfig.auth.contributor_agreements]]">
        <span class="contributorAgreementButton">
          <input id$="claNewAgreementsInput[[item.name]]"
              name="claNewAgreementsRadio"
              type="radio"
              data-name$="[[item.name]]"
              data-url$="[[item.url]]"
              on-tap="_handleShowAgreement"
              disabled$="[[_disableAggreements(item, _groups, _signedAgreements)]]">
          <label id="claNewAgreementsLabel">[[item.name]]</label>
        </span>
        <div class$="alreadySubmittedText [[_hideAggreements(item, _groups, _signedAgreements)]]">
          协议已经提交.
        </div>
        <div class="agreementsUrl">
          [[item.description]]
        </div>
      </template>
      <div id="claNewAgreement" class$="[[_computeShowAgreementsClass(_showAgreements)]]">
        <h3 class="smallHeading">审查此协议:</h3>
        <div id="agreementsUrl" class="agreementsUrl">
          <a href$="[[_agreementsUrl]]" target="blank" rel="noopener">
            请检查此协议.</a>
        </div>
        <div class$="agreementsTextBox [[_computeHideAgreementClass(_agreementName, _serverConfig.auth.contributor_agreements)]]">
          <h3 class="smallHeading">完成此协议:</h3>
          <input id="input-agreements" is="iron-input" bind-value="{{_agreementsText}}" placeholder="Enter 'I agree' here" />
          <gr-button on-tap="_handleSaveAgreements" disabled="[[_disableAgreementsText(_agreementsText)]]">
            提交
          </gr-button>
        </div>
      </div>
    </main>
    <gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
  </template>
  <script src="gr-cla-view.js"></script>
</dom-module>
